﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace dzs.Web.qualitysked3
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int qid=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(qid);
				}
			}
		}
			
	private void ShowInfo(int qid)
	{
		dzs.BLL.qualitysked3 bll=new dzs.BLL.qualitysked3();
		dzs.Model.qualitysked3 model=bll.GetModel(qid);
		this.lblqid.Text=model.qid.ToString();
		this.txtspotunit.Text=model.spotunit;
		this.txtprojectname.Text=model.projectname;
		this.txtsupplier.Text=model.supplier;
		this.txtproductname.Text=model.productname;
		this.txtptype.Text=model.ptype;
		this.txtwinnum.Text=model.winnum.ToString();
		this.txtproductdw.Text=model.productdw;
		this.txtprojectunit.Text=model.projectunit;
		this.txtspotopinion.Text=model.spotopinion;
		this.txtplandate.Text=model.plandate.ToString();
		this.txtuid.Text=model.uid.ToString();
		this.txtqresult.Text=model.qresult;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtspotunit.Text.Trim().Length==0)
			{
				strErr+="抽检实施单位不能为空！\\n";	
			}
			if(this.txtprojectname.Text.Trim().Length==0)
			{
				strErr+="projectname不能为空！\\n";	
			}
			if(this.txtsupplier.Text.Trim().Length==0)
			{
				strErr+="supplier不能为空！\\n";	
			}
			if(this.txtproductname.Text.Trim().Length==0)
			{
				strErr+="productname不能为空！\\n";	
			}
			if(this.txtptype.Text.Trim().Length==0)
			{
				strErr+="ptype不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtwinnum.Text))
			{
				strErr+="winnum格式错误！\\n";	
			}
			if(this.txtproductdw.Text.Trim().Length==0)
			{
				strErr+="productdw不能为空！\\n";	
			}
			if(this.txtprojectunit.Text.Trim().Length==0)
			{
				strErr+="projectunit不能为空！\\n";	
			}
			if(this.txtspotopinion.Text.Trim().Length==0)
			{
				strErr+="spotopinion不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtplandate.Text))
			{
				strErr+="plandate格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtuid.Text))
			{
				strErr+="uid格式错误！\\n";	
			}
			if(this.txtqresult.Text.Trim().Length==0)
			{
				strErr+="qresult不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int qid=int.Parse(this.lblqid.Text);
			string spotunit=this.txtspotunit.Text;
			string projectname=this.txtprojectname.Text;
			string supplier=this.txtsupplier.Text;
			string productname=this.txtproductname.Text;
			string ptype=this.txtptype.Text;
			decimal winnum=decimal.Parse(this.txtwinnum.Text);
			string productdw=this.txtproductdw.Text;
			string projectunit=this.txtprojectunit.Text;
			string spotopinion=this.txtspotopinion.Text;
			DateTime plandate=DateTime.Parse(this.txtplandate.Text);
			int uid=int.Parse(this.txtuid.Text);
			string qresult=this.txtqresult.Text;


			dzs.Model.qualitysked3 model=new dzs.Model.qualitysked3();
			model.qid=qid;
			model.spotunit=spotunit;
			model.projectname=projectname;
			model.supplier=supplier;
			model.productname=productname;
			model.ptype=ptype;
			model.winnum=winnum;
			model.productdw=productdw;
			model.projectunit=projectunit;
			model.spotopinion=spotopinion;
			model.plandate=plandate;
			model.uid=uid;
			model.qresult=qresult;

			dzs.BLL.qualitysked3 bll=new dzs.BLL.qualitysked3();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","List.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
